'use strict';
app.factory('RejectedService', function(HttpUtilService,$q) {
        /***
         * 获取退货原因
         * @param user_id 用户id
         * @param goods_id int 货物id
         * @param version 版本号
         * @param token
         * @returns {AnimateRunner.promise|*|qFactory.Deferred.promise|td.f.promise|f.promise}
         * {
         * rejected_type JSON格式的退货原因
         * }
         */
        function getRejectedType(user_id,goods_id,version,token){
            var deferred = $q.defer();
            HttpUtilService.httpGetHasToken("Rejected/RejectedType",{user_id:user_id,goods_id:goods_id,version:version},token)
                .then(function (response) {
                    if(response.code == "000000"){
                        deferred.resolve(response.ProvisionInfo)
                    } else {
                        console.log("getRejectedType code:"+ response.code)
                    }
                },function (error) {
                    console.log("getRejectedType error:"+ error)
                })
            return deferred.promise;
        }

        /***
         * 创建退货单
         * @param user_id 用户id
         * @param goods_id 货物id
         * @param seller_id 商家id
         * @param token
         * @returns {AnimateRunner.promise|*|qFactory.Deferred.promise|td.f.promise|f.promise}
         * {
         * goods_id int 商品id
         * picture 商品地址
         * goods_array 商品和货品名称 name和规格 value 串 json数据格式({"name":"法国进口红酒 塞莱斯城堡干红葡萄酒 整箱装 750ml*6瓶","goods_id":"2207667","value":"颜色:红"})
         * goods_price float 原价
         * real_price float 实付金额
         * order_id 订单号
         * pay_type int 支付方式
         * rejected_type 退款方式
         * reason 退货原因
         * }
         */
        function createRejected(user_id,goods_id,seller_id,token){
            var deferred = $q.defer();
            HttpUtilService.httpGetHasToken("Rejected/RejectedType",{user_id:user_id,goods_id:goods_id,seller_id:seller_id},token)
                .then(function (response) {
                    if(response.code == "000000"){
                        deferred.resolve(response.ProvisionInfo)
                    } else {
                        console.log("createRejected code:"+ response.code)
                    }
                },function (error) {
                    console.log("createRejected error:"+ error)
                })
            return deferred.promise;
        }
        return {
            getRejectedType:getRejectedType,
            createRejected:createRejected
        }
    })

